import {
  GetCurrentDateTime
} from '@/api/base'
export default {
  data() {
    return {
      visible: false,
      formLoading: false,
      btnLoading: false,
      subjectTable: [],
      dataForm: {
        url: '',
      },
      dataRule :{
        url: [
          { required: true, message: '请输入考点服务地址', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(row) {
      this.dataForm.url = this.$store.getters.baseUrl
      this.visible = true
      this.formLoading = true
      this.$nextTick(() => {
        this.listLoading = false
      })
      this.formLoading = false
    },
    onCeshi() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.btnLoading = true
          this.$store
            .dispatch("base/changeCeshiUrl", this.dataForm.url).then(() => {
            GetCurrentDateTime().then(res => {

              this.$message({
                message: '连接成功！',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.btnLoading = false
                }
              })
            }).catch(() => {
              this.$message({
                message: '连接失败，请检查服务器地址',
                type: 'error',
                duration: 1500,
                onClose: () => {
                  this.btnLoading = false
                }
              })
            })
            /**/
          })
          // this.btnLoading = true
        }
      })
    },
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$store
            .dispatch("base/changeServiceUrl", this.dataForm.url).then(() => {
            this.$message({
              message: '修改成功！',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.btnLoading = false
                this.$emit('refreshDataList')
              }
            })
          })
          // this.btnLoading = true
        }
      })
    }
  }
}
